package week3;

public class DrieMacht
{
	public DrieMacht()
	{
		int n = 81*81*81;
		System.out.println(isDrieMachtv1(n));
		System.out.println(isDrieMachtv2(n));
	}
	
	public boolean isDrieMachtv1(int n)
	{
		long r = 0;
		long g = n;
		for(int i = 0; r<g;i++)
		{
			r = pow(3,i);
		}
		return r == g;
	}
	
	public boolean isDrieMachtv2(int n)
	{
		int nn = n / 3;
		if(n < 1 || n == 2)
		{
			return false;
		}
		else if(n == 1 || n == 3)
		{
			return true;
		}
		else if(n>3)
		{
			if(nn*3 != n)
			{
				return false;
			}
			if(n%3==0)
			{
				return isDrieMachtv2(n / 3);
			}
		}
		return false;
	}
	
	private long pow(long a, long b)
	{
		if(b == 0)
			return 1;
		return a * pow(a,b-1);
	}

	/**
	 * @param args
	 */
	public static void main(String[] args)
	{
		// TODO Auto-generated method stub
		new DrieMacht();
	}
	
}
